<template>
  <div>
    <el-form  :model="ruleForm" status-icon :rules="rules" ref="ruleForm"
     :inline="true" class="demo-ruleForm">
      <el-form-item label="日期时间范围:">
        <div class="block">
          <el-date-picker
            v-model="dates"
            type="datetimerange"
            :picker-options="pickerOptions"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
            align="right">
          </el-date-picker>
        </div>
      </el-form-item>
      <el-form-item  label="车牌号:" prop="vehicle_code">
        <el-input v-model=ruleForm.vehicle_code  autocomplete="off"  placeholder="vehicle_code"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="submitForm('ruleForm')" >查询</el-button>
      </el-form-item>
    </el-form>
    <el-table
      :data="pageInfo.list"
      border
      align="center"
      stripe
      :cell-style="view"
      ref="multipleTable"
      tooltip-effect="dark"
      style="
        border-radius: 30px;
        width: 80%;
        margin: 0px auto;
        box-shadow: 0 2px 4px rgba(0, 0, 0, 0.12), 0 0 6px rgba(0, 0, 0, 0.04);
      ">

      <el-table-column type="selection" width="60%" prop="id"> </el-table-column>
      <el-table-column
        prop="order_id"
        label="订单Id"
        width="80"></el-table-column>
      <el-table-column prop="order_vehicle_code" label="车牌号" width="120%">
      </el-table-column>
      <el-table-column prop="order_startime" label="开始时间" width="180%">
      </el-table-column>
      <el-table-column prop="order_endtime" label="结束时间" width="180%">
      </el-table-column>
      <el-table-column prop="order_money" label="金额" width="100%">
      </el-table-column>
      <el-table-column prop="order_state" label="订单状态" width="110%">
      </el-table-column>
      <el-table-column label="订单确认" width="180%"  v-if=this.isview>
        <template slot-scope="scope">
          <el-button type="primary" round   @click="stall_view(scope.row)">确认交易完成</el-button>
        </template>
      </el-table-column>
    </el-table>

    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="pageInfo.pageNum"
      :page-sizes="[3, 5, 10, 15, 20]"
      :page-size="pageInfo.pageSize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="pageInfo.total">
    </el-pagination>
  </div>
</template>
<script>
export default {
  data() {
    let rule1 = /^$|^([京津晋冀蒙辽吉黑沪苏浙皖闽赣鲁豫鄂湘粤桂琼渝川贵云藏陕甘青宁新][ABCDEFGHJKLMNPQRSTUVWXY][1-9DF][1-9ABCDEFGHJKLMNPQRSTUVWXYZ]\d{3}[1-9DF]|[京津晋冀蒙辽吉黑沪苏浙皖闽赣鲁豫鄂湘粤桂琼渝川贵云藏陕甘青宁新][ABCDEFGHJKLMNPQRSTUVWXY][\dABCDEFGHJKLNMxPQRSTUVWXYZ]{5})$/;
     var validateVehicle_code = (rule, value, callback) => {
       if(!rule1.test(value)) {
          callback(new Error('请输入正确车牌号'));
        } 
        callback();
      };
    return {
      rules: {
        vehicle_code: [
          { validator: validateVehicle_code, trigger: 'blur' }
        ],
      },
      ruleForm: {
          vehicle_code:'',
        },
      pickerOptions: {
          shortcuts: [{
          text: '最近一周',
          onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
              picker.$emit('pick', [start, end]);
            }
          }]
      },
        pageInfo: {},
        pageSize: 3,
        currentPage: 1,
        dates:'',
        isview:null
    };
  },
  methods: {
    submitForm(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
         this.zt_select_Order();
        } else {
          alert('error submit!!');
        }
      });
    },
    zt_select_Order(){
      var id = sessionStorage.getItem('userId');
      this.$axios
        .get("/zt_selectOrderAll", {
          params: {
            pageSize: this.pageSize,
            currentPage: this.currentPage,
            date1:this.dates[0],
            date2:this.dates[1],
            vehicle_code:this.ruleForm.vehicle_code,
            user_id:id
          }
        })
        .then((res) => {
          this.pageInfo = res.data.data;
          this.ruleForm.vehicle_code = "";
        })
        .catch((error) => {
          console.log(error);
        });
    },
    handleSizeChange(val) {
      this.pageSize = val;
      this.currentPage = 1;
      this.zt_select_Order();
      console.log(`每页 ${val} 条`);
    },
    handleCurrentChange(val) {
      this.currentPage = val;
      this.zt_select_Order();
      console.log(`当前页: ${val}`);
    },
    view({row}){
        if(row.order_state == "已完成"){
            this.isview = false;
        }
    }
  },
  mounted() {
    this.zt_select_Order();
  },
};
</script>